using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

using SharpCore.Data;

namespace TF.Access {
	public partial class Tf_pic {
		#region Fields
		private int id;
		private int album_id;
		private string album_name;
		private string title;
		private string pic_url;
		private string memo;
		private string note;
		private string public_type;
		private int owner_id;
		private DateTime upload_date = System.Data.SqlTypes.SqlDateTime.MinValue.Value;
		#endregion
		
		#region Constructors
		/// <summary>
		/// Initializes a new instance of the Tf_pic class.
		/// </summary>
		public Tf_pic() {
		}
		
		/// <summary>
		/// Initializes a new instance of the Tf_pic class.
		/// </summary>
		public Tf_pic(int album_id, string album_name, string title, string pic_url, string memo, string note, string public_type, int owner_id, DateTime upload_date) {
			this.album_id = album_id;
			this.album_name = album_name;
			this.title = title;
			this.pic_url = pic_url;
			this.memo = memo;
			this.note = note;
			this.public_type = public_type;
			this.owner_id = owner_id;
			this.upload_date = upload_date;
		}
		
		/// <summary>
		/// Initializes a new instance of the Tf_pic class.
		/// </summary>
		public Tf_pic(int id, int album_id, string album_name, string title, string pic_url, string memo, string note, string public_type, int owner_id, DateTime upload_date) {
			this.id = id;
			this.album_id = album_id;
			this.album_name = album_name;
			this.title = title;
			this.pic_url = pic_url;
			this.memo = memo;
			this.note = note;
			this.public_type = public_type;
			this.owner_id = owner_id;
			this.upload_date = upload_date;
		}
		#endregion
		
		#region Properties
		/// <summary>
		/// Gets or sets the Id value.
		/// </summary>
		public int Id {
			get { return id; }
			set { id = value; }
		}
		
		/// <summary>
		/// Gets or sets the Album_id value.
		/// </summary>
		public int Album_id {
			get { return album_id; }
			set { album_id = value; }
		}
		
		/// <summary>
		/// Gets or sets the Album_name value.
		/// </summary>
		public string Album_name {
			get { return album_name; }
			set { album_name = value; }
		}
		
		/// <summary>
		/// Gets or sets the Title value.
		/// </summary>
		public string Title {
			get { return title; }
			set { title = value; }
		}
		
		/// <summary>
		/// Gets or sets the Pic_url value.
		/// </summary>
		public string Pic_url {
			get { return pic_url; }
			set { pic_url = value; }
		}
		
		/// <summary>
		/// Gets or sets the Memo value.
		/// </summary>
		public string Memo {
			get { return memo; }
			set { memo = value; }
		}
		
		/// <summary>
		/// Gets or sets the Note value.
		/// </summary>
		public string Note {
			get { return note; }
			set { note = value; }
		}
		
		/// <summary>
		/// Gets or sets the Public_type value.
		/// </summary>
		public string Public_type {
			get { return public_type; }
			set { public_type = value; }
		}
		
		/// <summary>
		/// Gets or sets the Owner_id value.
		/// </summary>
		public int Owner_id {
			get { return owner_id; }
			set { owner_id = value; }
		}
		
		/// <summary>
		/// Gets or sets the Upload_date value.
		/// </summary>
		public DateTime Upload_date {
			get { return upload_date; }
			set { upload_date = value; }
		}
		#endregion
		
		#region Methods
		/// <summary>
		/// Saves a record to the tf_pics table.
		/// </summary>
		public void Insert() {
			id = Convert.ToInt32(SqlClientUtility.ExecuteScalar("tf_picsInsert", album_id, album_name, title, pic_url, memo, note, public_type, owner_id, upload_date));
		}
		
		/// <summary>
		/// Updates a record in the tf_pics table.
		/// </summary>
		public void Update() {
			SqlClientUtility.ExecuteNonQuery("tf_picsUpdate", id, album_id, album_name, title, pic_url, memo, note, public_type, owner_id, upload_date);
		}
		
		/// <summary>
		/// Deletes a record from the tf_pics table by its primary key.
		/// </summary>
		public void Delete() {
			SqlClientUtility.ExecuteNonQuery("tf_picsDelete", id);
		}
		
		/// <summary>
		/// Selects a single record from the tf_pics table.
		/// </summary>
		public static Tf_pic Select(int id) {
			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader("tf_picsSelect", id)) {
				if (dataReader.Read()) {
					return MakeTf_pic(dataReader);
				} else {
					return null;
				}
			}
		}
		
		/// <summary>
		/// Selects all records from the tf_pics table.
		/// </summary>
		public static List<Tf_pic> SelectAll() {
			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader("tf_picsSelectAll")) {
				List<Tf_pic> tf_picList = new List<Tf_pic>();
				while (dataReader.Read()) {
					Tf_pic tf_pic = MakeTf_pic(dataReader);
					tf_picList.Add(tf_pic);
				}
				return tf_picList;
			}
		}
		
		/// <summary>
		/// Creates a new instance of the tf_pics class and populates it with data from the specified SqlDataReader.
		/// </summary>
		private static Tf_pic MakeTf_pic(SqlDataReader dataReader) {
			Tf_pic tf_pic = new Tf_pic();
			
			if (dataReader.IsDBNull(0) == false) {
				tf_pic.Id = dataReader.GetInt32(0);
			}
			if (dataReader.IsDBNull(1) == false) {
				tf_pic.Album_id = dataReader.GetInt32(1);
			}
			if (dataReader.IsDBNull(2) == false) {
				tf_pic.Album_name = dataReader.GetString(2);
			}
			if (dataReader.IsDBNull(3) == false) {
				tf_pic.Title = dataReader.GetString(3);
			}
			if (dataReader.IsDBNull(4) == false) {
				tf_pic.Pic_url = dataReader.GetString(4);
			}
			if (dataReader.IsDBNull(5) == false) {
				tf_pic.Memo = dataReader.GetString(5);
			}
			if (dataReader.IsDBNull(6) == false) {
				tf_pic.Note = dataReader.GetString(6);
			}
			if (dataReader.IsDBNull(7) == false) {
				tf_pic.Public_type = dataReader.GetString(7);
			}
			if (dataReader.IsDBNull(8) == false) {
				tf_pic.Owner_id = dataReader.GetInt32(8);
			}
			if (dataReader.IsDBNull(9) == false) {
				tf_pic.Upload_date = dataReader.GetDateTime(9);
			}

			return tf_pic;
		}
		#endregion
	}
}
